<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="nav">导航</div>
    <div id="container"></div>
    <script>
        var text = document.createElement("p");
        var content = document.createTextNode("我是文本");

        var id = document.createAttribute("id");
        text.appendChild(content);
        id.value = "root";
        text.setAttributeNode(id);
        console.log(text);

        var container=document.getElementById("container");
        //console.log(container);
        container.appendChild(text);
    </script>
</body>

</html>